
// src/hooks/useNotification.ts
import { notification } from 'antd';
import { useCallback } from 'react';

/**
 * 通知 Hook - 封装 Ant Design 通知
 */
export const useNotification = () => {
  const [api, contextHolder] = notification.useNotification();

  const showSuccess = useCallback(
    (message: string, description?: string) => {
      api.success({
        message,
        description,
        placement: 'topRight',
      });
    },
    [api]
  );

  const showError = useCallback(
    (message: string, description?: string) => {
      api.error({
        message,
        description,
        placement: 'topRight',
        duration: 0, // 错误通知不自动关闭
      });
    },
    [api]
  );

  const showWarning = useCallback(
    (message: string, description?: string) => {
      api.warning({
        message,
        description,
        placement: 'topRight',
      });
    },
    [api]
  );

  const showInfo = useCallback(
    (message: string, description?: string) => {
      api.info({
        message,
        description,
        placement: 'topRight',
      });
    },
    [api]
  );

  return {
    contextHolder,
    showSuccess,
    showError,
    showWarning,
    showInfo,
  };
};
